package com.lebang.medicalInquiry.controller;


import com.lebang.medicalInquiry.constant.ResponseEnum;
import com.lebang.medicalInquiry.model.po.*;
import com.lebang.medicalInquiry.model.vo.PageVo;
import com.lebang.medicalInquiry.model.vo.SubjectClassifyVo;
import com.lebang.medicalInquiry.model.vo.admin.PhysicianListVo;
import com.lebang.medicalInquiry.model.vo.admin.SubjectClassifyListVo;
import com.lebang.medicalInquiry.response.Callback;
import com.lebang.medicalInquiry.response.JsonData;
import com.lebang.medicalInquiry.service.PhysicianService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.util.List;

@RequestMapping("/physician")
@Api(tags = "医师相关接口")
@RestController
@Validated
public class PhysicianController {

    @Value("${digital.merchant_id}")
    private String merchantId;

    @Autowired
    private PhysicianService service;


    @GetMapping("/position")
    @ApiOperation("查询医师所有职务")
    public JsonData<List<String>> getAllPosition(HttpServletRequest request, HttpServletResponse response) {


        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo(), service.getAllPosition());

    }

    @GetMapping("/")
    @ApiOperation("医师列表")
    public JsonData<PageVo<List<PhysicianListVo>>> listArticle(HttpServletRequest request, HttpServletResponse response,
                                                               @ApiParam(name = "name", value = "名称") @RequestParam(value = "name", required = false) String name,
                                                               @ApiParam(name = "organizationId", value = "机构id") @RequestParam(value = "organizationId", required = false) Integer organizationId,
                                                               @ApiParam(name = "organizationOperatorUuid", value = "机构运营人员Uuid") @RequestParam(value = "organizationOperatorUuid", required = false) String organizationOperatorUuid,
                                                               @ApiParam(name = "classifyId", value = "直播专题id") @RequestParam(value = "classifyId", required = false) Integer classifyId,
                                                               @ApiParam(name = "state", value = "0 禁用 1 启用 -1 所有") @RequestParam(value = "state", required = false, defaultValue = "-1") Integer state,
                                                               @ApiParam(name = "page", value = "页码") @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                               @ApiParam(name = "limit", value = "条数") @RequestParam(value = "limit", defaultValue = "10") Integer limit) {

        PageVo<List<PhysicianListVo>> list = service.getList(name, classifyId, organizationId, organizationOperatorUuid, state, page, limit);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo(), list);

    }

    @PostMapping("/")
    @ApiOperation("修改医师数据")
    public JsonData operator(HttpServletRequest request, HttpServletResponse response
            , @RequestBody Physician po

    ) {


        service.operator(po);

        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());

    }


    @DeleteMapping("/{id}")
    @ApiOperation("删除医师文章")
    public JsonData remove(HttpServletRequest request, HttpServletResponse response
            , @ApiParam(name = "id", value = "id", required = true) @PathVariable Integer id

    ) {

        service.remove(id,merchantId);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());

    }


    @GetMapping("/case")
    @ApiOperation("查询医师案例")
    public JsonData<PageVo<List<PhysicianCase>>> listPhysicianCase(HttpServletRequest request, HttpServletResponse response,
                                                                   @ApiParam(name = "physicianId", value = "医师id") @NotNull(message = "physicianId 必传")
                                                                   @RequestParam(value = "physicianId", required = false, defaultValue = "-1") Integer physicianId,
                                                                   @ApiParam(name = "type", value = "0 医师 1 机构") @NotNull(message = "type 不能为空")
                                                                   @RequestParam(value = "type", required = false) Integer type,
                                                                   @ApiParam(name = "page", value = "页码") @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                                   @ApiParam(name = "limit", value = "条数") @RequestParam(value = "limit", defaultValue = "10") Integer limit) {

        PageVo<List<PhysicianCase>> list = service.listPhysicianCase(physicianId, type, page, limit);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo(), list);

    }


    @PostMapping("/case")
    @ApiOperation("修改医师案例")
    public JsonData operatorCase(HttpServletRequest request, HttpServletResponse response
            , @RequestBody PhysicianCase po

    ) {


        service.operatorCase(po);

        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());

    }

    @DeleteMapping("/case/{id}")
    @ApiOperation("删除医师案例")
    public JsonData removePhysicianCase(HttpServletRequest request, HttpServletResponse response
            , @ApiParam(name = "id", value = "id", required = true) @PathVariable Integer id

    ) {

        service.removePhysicianCase(id);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());

    }

    @GetMapping("/live/status/{physicianId}")
    @ApiOperation("直播状态操作")
    public JsonData liveStatus(HttpServletRequest request, HttpServletResponse response
            , @ApiParam(name = "id", value = "id", required = true) @PathVariable Integer physicianId
            , @ApiParam(name = "type", value = "type:start,close", required = true) @RequestParam(required = false) String type

    ) {
        service.liveStatus(physicianId,type,merchantId);

        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());

    }


    @GetMapping("/classify")
    @ApiOperation("查询医学直播分类")
    public JsonData<PageVo<List<SubjectClassifyListVo>>> listClassify(HttpServletRequest request, HttpServletResponse response,
                                                                      @ApiParam(name = "parentId", value = "父级id,不传默认查询一级标签") @RequestParam(value = "parentId", required = false) Integer parentId,
                                                                      @ApiParam(name = "state", value = "0 禁用 1 启用 -1 所有") @RequestParam(value = "state", required = false, defaultValue = "-1") Integer state,
                                                                      @ApiParam(name = "page", value = "页码") @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                                      @ApiParam(name = "limit", value = "条数") @RequestParam(value = "limit", defaultValue = "10") Integer limit) {

        PageVo<List<SubjectClassifyListVo>> list = service.listClassify(parentId, state, page, limit);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo(), list);

    }


    @PostMapping("/classify")
    @ApiOperation("修改医师直播分类")
    public JsonData operatorSubjectClassify(HttpServletRequest request, HttpServletResponse response
            , @RequestBody SubjectClassify subjectClassify

    ) {


        service.operatorClassify(subjectClassify);

        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());

    }

    @DeleteMapping("/classify/{id}")
    @ApiOperation("删除医师直播分类")
    public JsonData removeSubjectClassify(HttpServletRequest request, HttpServletResponse response
            , @ApiParam(name = "id", value = "id", required = true) @PathVariable Integer id

    ) {

        service.removeClassify(id);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());

    }

    @GetMapping("/verbal/trick/{physicianId}")
    @ApiOperation("查询医生话术库")
    public JsonData<PageVo<List<PhysicianVerbalTrick>>> getVerbalTrick(HttpServletRequest request, HttpServletResponse response
            , @ApiParam(name = "physicianId", value = "physicianId", required = true) @PathVariable Integer physicianId
            , @ApiParam(name = "type", value = "convention:常规话术库 qa：问答话术库") @RequestParam(value = "type", required = false) String type
            , @ApiParam(name = "page", value = "页码") @RequestParam(value = "page", defaultValue = "1") Integer page
            , @ApiParam(name = "limit", value = "条数") @RequestParam(value = "limit", defaultValue = "10") Integer limit
    ) {

        PageVo<List<PhysicianVerbalTrick>> verbalTrick = service.getVerbalTrick(physicianId, type, page, limit);

        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo(), verbalTrick);

    }

    @PostMapping("/verbal/trick")
    @ApiOperation("新增或修改医生话术库")
    public JsonData<PageVo<List<PhysicianVerbalTrick>>> modifyTrick(HttpServletRequest request, HttpServletResponse response,
                                                                    @RequestBody PhysicianVerbalTrick physicianVerbalTrick
    ) {

        service.modifyTrick(physicianVerbalTrick,merchantId);

        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());

    }

    @DeleteMapping("/verbal/trick/{physicianId}")
    @ApiOperation("删除医生话术库")
    public JsonData removeTrick(HttpServletRequest request, HttpServletResponse response
            , @ApiParam(name = "physicianId", value = "physicianId", required = true) @PathVariable Integer physicianId
    ) {

        service.removeTrick(physicianId,merchantId);

        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());

    }


//    @DeleteMapping("/live/schedule/{physicianId}")
//    @ApiOperation("查询医师视频生成进度")
//    public JsonData getLiveSchedule(HttpServletRequest request, HttpServletResponse response
//            , @ApiParam(name = "physicianId", value = "physicianId", required = true) @PathVariable Integer physicianId
//    ) {
//
//        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo(), service.schedule(physicianId,merchantId));
//
//    }


}